package com.hs.wa.service;


import com.springnew.dao.PersonMapper;
import com.springnew.model.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    private PersonMapper personMapper;
    @Autowired

    private JdbcTemplate jdbcTemplate;


    public boolean addUser(Person user) {
        boolean flag = !!(personMapper.insert(user) > 0);
        return flag;
    }

    public boolean selectUser(Person user) {


        String sql = "select username from User where username='" + user.getUsername() + "' and password='" + user.getPassword() + "'";

        Map<String, Object> map = jdbcTemplate.queryForMap(sql);
        Object username = map.get("username");
        if ("".equals(username)) {
            return false;
        }
        System.out.println(username);
        return true;
    }
}
